#!/usr/bin/env python
# -*- coding: utf-8 -*-
#hacer una documentacion decente
#implementar operaciones urm
import lectura
import turtle
import turtugas
comandos= []
archivo = "pruebas.txt"
def main():
	linea = lectura.abrir_archivo(archivo)
	
	wn=turtle.Screen()
	
	for i in range(len(linea)):
		
		if linea[i][0]=="P" and linea[i][1]=="(":
	            
		    print("instruction point")
		    labelspoints= []
		    for j in range (1,len(linea[i])):
		        if linea[i][j] != "," and linea[i][j] != ")" and linea[i][j] != "(" and linea[i][j] != "\n":
		            labelspoints.append(linea[i][j])
                    
		    comandos.append(turtugas.genpoints(labelspoints))
                              
				 
                                   
                elif linea[i][0]=="C":
		    print("instruction circulo")	
	            labelsc= []
		    for j in range (1,len(linea[i])):
		        if linea[i][j] != "," and linea[i][j] != ")" and linea[i][j] != "(" and linea[i][j] != "\n":
		            labelsc.append(linea[i][j])
                    
		    comandos.append(turtugas.gencircle(labelsc))
		elif linea[i][0]=="L"and linea[i][1]=="C":
			lcircles=[]
                        for j in range (2,len(linea[i])):  
		            if linea[i][j] != "," and linea[i][j] != ")" and linea[i][j] != "(" and linea[i][j] != "\n" and linea[i][j] != ";":
		                lcircles.append(linea[i][j])
			comandos.append(turtugas.gencirclelabel(lcircles))
                        print("label circulo")
		
		elif linea[i][0]=="L" and linea[i][1]=="(":
                        labelslines=[]
                        for j in range (1,len(linea[i])):
		            if linea[i][j] != "," and linea[i][j] != ")" and linea[i][j] != "(" and linea[i][j] != "\n":
		                labelslines.append(linea[i][j])
			comandos.append(turtugas.genlines(labelslines))
                        print ("linea instruction")
                     
		
		elif linea[i][0]=="L" and linea[i][1]=="L": 
			print("label linea")
		        llines=[]
                        for j in range (2,len(linea[i])):  
		            if linea[i][j] != "," and linea[i][j] != ")" and linea[i][j] != "(" and linea[i][j] != "\n" and linea[i][j] != ";":
		                llines.append(linea[i][j])
			comandos.append(turtugas.genlinelabel(llines))
                        print ("linea label instruction")
                  
		elif linea[i][0]=="L" and linea[i][1]=="P":
                        lintersect=[]
                        for j in range (2,len(linea[i])):  
		            if linea[i][j] != "," and linea[i][j] != ")" and linea[i][j] != "(" and linea[i][j] != "\n" and linea[i][j] != ";":
		                lintersect.append(linea[i][j])
			comandos.append(turtugas.genlintersect(lintersect))
                        print ("linea label instruction")
			
		
		elif linea[i][0]=="D":
                        deletelabel= []
		        for j in range (1,len(linea[i])):
		              if  linea[i][j] != ")" and linea[i][j] != "(" and linea[i][j] != "\n":
		                  deletelabel.append(linea[i][j])
                        comandos.append(turtugas.gendeletelabel(deletelabel))
			print("borrar label")
                elif linea[i][0]=="G" and linea[i][1]=="I":  #go to x if  
			print("pertece a(checkinstruction) ")
		        checks=[]
                        
                        for j in range (5,len(linea[i])):  
		            if linea[i][j] != "," and linea[i][j] != ")" and linea[i][j] != "(" and linea[i][j] != "\n":
		                checks.append(linea[i][j])
			if turtugas.gencheck(checks):
                           print ("Saltamos a instruccion")
                           salto=turtugas.saltonum(checks)
                           print(salto)
                           i=salto
	                else:
                           print("No pertenece, continuamos")
	
	wn.exitonclick()

main()
